package com.fuelwallet.model;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Handler;

import com.fuelwallet.view.BaseMapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay;

public class PlacesItemizedOverlay extends BalloonItemizedOverlay<OverlayItem> {
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	private Context mContext;
	private Handler mHandler;
	
	public PlacesItemizedOverlay(Drawable defaultMarker, MapView mapView, Handler handler) {
		super(boundCenter(defaultMarker), mapView);
		mContext = mapView.getContext();
		mHandler = handler;
		populate();
	}
	
	public void addOverlay(OverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	}
	
	
	public void clearOverlayItems(){
		mOverlays.clear();	
		setLastFocusedIndex(-1);
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}
	
	@Override
	protected boolean onBalloonTap(int index) {
		mHandler.obtainMessage(BaseMapActivity.MESSAGE_LAUNCH_DIRECTION, index, -1).sendToTarget();
		return true;
	}
}
